package stream;

import java.util.Arrays;
import java.util.List;

/**
 * @author mubei
 * @date 2021/11/22
 * @description
 */
public class Test {

    /*
    *题目要求
    *现在有5个用户 筛选
    * 1. ID为偶数
    * 2.年龄>23
    * 3.用户名大写
    * 4.用户名字母倒着排序
    * 5.只输出一个
    * */
    public static void main(String[] args) {
        User user1 = new User(1, "ah", 21);
        User user2 = new User(2, "b", 22);
        User user3 = new User(3, "c", 23);
        User user4 = new User(4, "d", 24);
        User user5 = new User(5, "e", 25);
        //集合存储
        List<User> list = Arrays.asList(user1, user2, user3, user4, user5);
        //计算交给流
        list.stream()
                .filter(r -> r.id%2==0 && r.age >23)
                .map(u -> u.name.toUpperCase())
                .sorted((u1,u2)->u1.compareTo(u2))
                .limit(1)
                .forEach(System.out::println);

    }
}

class User{
    int id;
    String name;
    int age;

    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }


}
